const { DataTypes } = require("sequelize");
const sequelize = require("./index");

const Product = sequelize.define(
    "product",
    {
        id: {
            type: DataTypes.INTEGER,
            primaryKey: true,
            allowNull: false,
            autoIncrement: true,
        },
        title: {
            type: DataTypes.STRING,
            allowNull: false,
        },
        count: {
            type: DataTypes.INTEGER,
            allowNull: false,
        },
        price: {
            type: DataTypes.DOUBLE,
            allowNull: false,
        },
        detail: {
            type: DataTypes.STRING,
            allowNull: null,
        },
        typeId: {
            type: DataTypes.INTEGER,
        },
    },
    {
        timestamps: false,
    }
);

Product.associate = function ({ ProductImage, ProductLabel, Order, Type }) {
    Product.hasMany(ProductImage);
    Product.hasMany(ProductLabel);
    Product.hasMany(Order);
    Product.belongsTo(Type);
};

module.exports = Product;
